<?php
/*
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2002 Bharat Mediratta
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

// Hack prevention.
if (!empty($_REQUEST["GALLERY_BASEDIR"])) {
	print "Security violation\n";
	exit;
}
require("./init.php"); 
$myts =& MyTextSanitizer::getInstance();
// Hack check
if (!$gallery->user->canDeleteFromAlbum($gallery->album)) {
	exit;
}
if (isset($id)) {
	$index = $gallery->album->getPhotoIndex($id);
}
if (isset($confirm) && isset($id)) {
	if ($albumDelete) {
		/* Track down the corresponding photo index and remove it */
		$index = 0;
		for ($i = 1; $i <= sizeof($gallery->album->photos); $i++) {
		    $photo = $gallery->album->getPhoto($i);
		    if (isset($photo->isAlbumName) && !strcmp($photo->isAlbumName, $id)) {
			/* Found it */
			$index = $i;
			break;
		    }
		}
	}
	$gallery->album->deletePhoto($index);
	$gallery->album->save();
	dismissAndReload();
	return;
}
?>
<html>
<head>
<title><?php echo _XG_DELETE_PHOTO; ?></title>
<?php echo getStyleSheetLink() ?>
</head>
<body>
<?php
if ($gallery->album && isset($id)) {
	if (isset($albumDelete)) {
?>
<center><span class="popuphead"><?php echo _XG_DELETE_ALBUM; ?></span>
<br><br><?php echo _XG_DO_YOU_DELETE_ALBUM;?><br><br>
<?php
$myAlbum = new Album();
$myAlbum->load($id);
?>
<?php echo $myAlbum->getHighlightTag() ?><br><br>
<b><?php echo $myts->displayTarea($myts->stripSlashesGPC($myAlbum->fields['title'])) ?></b><br>
<br><?php echo $myts->displayTarea($myts->stripSlashesGPC($myAlbum->fields['description'])) ?><br>
<?php echo makeFormIntro("delete_photo.php", array('method' => 'post')); ?>
<input type="hidden" name=id value=<?php echo $id?>>
<input type="hidden" name="albumDelete" value=<?php echo $albumDelete?>>
<input type="submit" name="confirm" value="<?php echo _XG_DELETE;?>">
<input type="submit" value="<?php echo _XG_CANCEL;?>" onclick='parent.close()'>
</form>
<br>
<?php
	} else {
?>
<center><?php echo _XG_DO_YOU_DELETE_PHOTO;?><br><br>
<?php echo $gallery->album->getThumbnailTag($index) ?><br>
<?php echo $gallery->album->getCaption($index) ?><br>
<?php echo makeFormIntro("delete_photo.php", array('method' => 'post')); ?>
<input type="hidden" name=id value=<?php echo $id?>>
<input type="submit" name="confirm" value="<?php echo _XG_DELETE;?>">
<input type="submit" value="<?php echo _XG_CANCEL;?>" onclick='parent.close()'>
</form><br>
<?php
	}
} else {
	gallery_error(_XG_ERROR_NO_ALBUM_SELECT);
}
?>
</body>
</html>